package com.wallet.crypto.trustapp.createWallets;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.wallet.crypto.trustapp.R;

/**
 * Created by ${张奎勋} on 2018/5/8.
 */
public class WalletView extends FrameLayout {

    public OnNewWalletClickListener onNewWalletClickListener;
    public OnImportWalletClickListener onImportWalletClickListener;
    private View mTable1;
    private View mTable2;
    private View mTable3;
    private ViewPager mViewPager;
    private FrameLayout mBeginHome;

    public WalletView(Context context) {
        super(context);
    }

    public WalletView(Context context, int layoutId) {
        super(context);

        init(layoutId);
    }

    private void init(int layoutId) {
        LayoutInflater.from(getContext()).inflate(layoutId, this, true);
        mTable1 = findViewById(R.id.v_cw_table1);
        mTable2 = findViewById(R.id.v_cw_table2);
        mTable3 = findViewById(R.id.v_cw_table3);
        mViewPager = findViewById(R.id.wpager_cw);
        mBeginHome = findViewById(R.id.begin_home);
    }

    public void showBeginHome() {
        mTable1.setVisibility(GONE);
        mTable2.setVisibility(GONE);
        mTable3.setVisibility(GONE);
        mViewPager.setVisibility(GONE);
        mBeginHome.setVisibility(VISIBLE);

        findViewById(R.id.button).setOnClickListener(v -> showCreateWallet());
        findViewById(R.id.tv_cw_import).setOnClickListener(v -> {
            if (onImportWalletClickListener != null)
                onImportWalletClickListener.onImportWallet();
        });
    }

    public void showCreateWallet() {
        mTable1.setVisibility(VISIBLE);
        mTable2.setVisibility(VISIBLE);
        mTable3.setVisibility(VISIBLE);
        mViewPager.setVisibility(VISIBLE);
        mBeginHome.setVisibility(GONE);

        View[] views = {mTable1, mTable2, mTable3};

        if (mViewPager != null) {
            mViewPager.setOffscreenPageLimit(4);
            mViewPager.setAdapter(new IntroPagerAdapter(this, mViewPager, views));
        }
    }

    public void setOnNewWalletClickListener(OnNewWalletClickListener onNewWalletClickListener) {
        this.onNewWalletClickListener = onNewWalletClickListener;
    }

    public void setOnImportWalletClickListener(OnImportWalletClickListener onImportWalletClickListener) {
        this.onImportWalletClickListener = onImportWalletClickListener;
    }


    public interface OnNewWalletClickListener {
        void onNewWallet(String editable);
    }

    public interface OnImportWalletClickListener {
        void onImportWallet();
    }
}
